package com.kedacom.freedomLabel.printer;

import com.gprinter.command.LabelCommand;
import com.kedacom.freedomLabel.model.annotation.PrinterSettingCategory;

/**
 * @author licheng
 * @since 2019/11/29 14:37
 */
public final class GpPrinterOptions {

    private GpPrinterOptions() {

    }

    public static String getGpPrinterOptionValue(@PrinterSettingCategory String category, int dataIndex) {
        String value = null;
        switch (category) {
            case PrinterSettingCategory.GAP:
                String  gap = getGap(dataIndex);
                if (gap != null) {
                    value = gap;
                }
                break;
            case PrinterSettingCategory.SPEED:
                LabelCommand.SPEED speed = getSpeed(dataIndex);
                if (speed != null) {
                    value = String.valueOf(speed.getValue());
                }
                break;
            case PrinterSettingCategory.DIRECTION:
                LabelCommand.DIRECTION direction = getDirection(dataIndex);
                if (direction != null) {
                    value = String.valueOf(direction.getValue());
                }
                break;
            case PrinterSettingCategory.DENSITY:
                LabelCommand.DENSITY density = getDensity(dataIndex);
                if (density != null) {
                    value = String.valueOf(density.getValue());
                }
                break;
        }
        return value;
    }

    public static String getGap(int savePosition) {
        String[] gaps = getGap();
        if (savePosition < 0 || savePosition > gaps.length - 1) return null;
        return gaps[savePosition];
    }

    public static LabelCommand.SPEED getSpeed(int savePosition) {
        LabelCommand.SPEED[] speeds = getSpeed();
        if (savePosition < 0 || savePosition > speeds.length - 1) return null;
        return speeds[savePosition];
    }

    public static LabelCommand.DIRECTION getDirection(int savePosition) {
        LabelCommand.DIRECTION[] directions = getDirection();
        if (savePosition < 0 || savePosition > directions.length - 1) return null;
        return directions[savePosition];
    }

    public static String[] getGap() {
        String[] values = new String[]{"0","1","2","3","4","6"};
        return values;
    }
    public static LabelCommand.DENSITY getDensity(int savePosition) {
        LabelCommand.DENSITY[] densities = getDensity();
        if (savePosition < 0 || savePosition > densities.length - 1) return null;
        return densities[savePosition];
    }

    public static LabelCommand.SPEED[] getSpeed() {
        LabelCommand.SPEED[] data = new LabelCommand.SPEED[4];
        int offset = 0;
        data[offset++] = LabelCommand.SPEED.SPEED1DIV5;
        data[offset++] = LabelCommand.SPEED.SPEED2;
        data[offset++] = LabelCommand.SPEED.SPEED3;
        data[offset] = LabelCommand.SPEED.SPEED4;
        return data;
    }

    public static LabelCommand.DIRECTION[] getDirection() {
        LabelCommand.DIRECTION[] data = new LabelCommand.DIRECTION[2];
        int offset = 0;
        data[offset++] = LabelCommand.DIRECTION.FORWARD;
        data[offset] = LabelCommand.DIRECTION.BACKWARD;
        return data;
    }

    public static LabelCommand.DENSITY[] getDensity() {
        LabelCommand.DENSITY[] data = new LabelCommand.DENSITY[16];
        int offset = 0;
        data[offset++] = LabelCommand.DENSITY.DNESITY0;
        data[offset++] = LabelCommand.DENSITY.DNESITY1;
        data[offset++] = LabelCommand.DENSITY.DNESITY2;
        data[offset++] = LabelCommand.DENSITY.DNESITY3;
        data[offset++] = LabelCommand.DENSITY.DNESITY4;
        data[offset++] = LabelCommand.DENSITY.DNESITY5;
        data[offset++] = LabelCommand.DENSITY.DNESITY6;
        data[offset++] = LabelCommand.DENSITY.DNESITY7;
        data[offset++] = LabelCommand.DENSITY.DNESITY8;
        data[offset++] = LabelCommand.DENSITY.DNESITY9;
        data[offset++] = LabelCommand.DENSITY.DNESITY10;
        data[offset++] = LabelCommand.DENSITY.DNESITY11;
        data[offset++] = LabelCommand.DENSITY.DNESITY12;
        data[offset++] = LabelCommand.DENSITY.DNESITY13;
        data[offset++] = LabelCommand.DENSITY.DNESITY14;
        data[offset] = LabelCommand.DENSITY.DNESITY15;
        return data;
    }
}